package com.samoiloff.ui.list.simple {
	import com.samoiloff.util.data.PropItem;

	/**
	 * @author Damirr
	 */
	public class ScrollContSelectable extends ScrollCont {
		
		private var _selectedIndex: int;
		
		public function ScrollContSelectable(renderer: ISelectableRenderer) {
			_selectedIndex = -1;
			super(renderer);
		}
		
		override protected function updateChildren(): void {
			super.updateChildren();
			updateSelected();
		}
		
		private function updateSelected():void {
			for (var i:int = 0; i<length; i++) {
				var item:Object = getItemAt(i);
				item.selected = item.index == _selectedIndex;
			}
		}		public function selectByProp(propName:String, propValue:*):Boolean {
			for (var i:int = 0; i<length; i++) {
				var item:Object = getItemAt(i).data;
				if(item is PropItem){
					if((item as PropItem).getValueByProp(propName) == propValue) {
						selectedIndex = i;
						return true;
					}
				}
			}
			return false;
		}
		public function get selectedIndex(): int {
			return _selectedIndex;
		}
		
		public function set selectedIndex(selectedIndex: int): void {
			_selectedIndex = selectedIndex;
			updateSelected();
		}
	}
}
